package cn.com.infohold.smartcity.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.com.infohold.smartcity.R;
import cn.com.infohold.smartcity.activity.Landinfo.LandInfoDetail_Activity;
import cn.com.infohold.smartcity.activity.Warrant.WarrantDetail_Activity;
import cn.com.infohold.smartcity.api.bean.WarrantBean;
import cn.com.infohold.smartcity.parent.ParentActivity;
import library.utils.Utils;

/**
 * Created by Monsoon on 2017/11/3.
 */
public class Warrant_Adapter extends RecyclerView.Adapter<Warrant_Adapter.mViewHolder> {

    Context context;
    private List<WarrantBean> mList;

    public Warrant_Adapter(Context context, List<WarrantBean> mList) {
        this.context = context;
        this.mList = mList;
    }

    @Override
    public mViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mViewHolder viewHolder = new mViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_warrant, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(mViewHolder holder, int position) {
        WarrantBean bean = mList.get(position);
        holder.tv_contractnumber.setText(bean.getContractnumber());
        switch (bean.getStatus()){
            case 1:
                holder.tv_status.setText("保存");
                break;
            case 2:
                holder.tv_status.setText("提交一级审批");
                break;
            case 3:
                holder.tv_status.setText("一级审批未通过");
                break;
            case 4:
                holder.tv_status.setText("一级审批关闭");
                break;
            case 5:
                holder.tv_status.setText("待二级审批");
                break;
            case 6:
                holder.tv_status.setText("二级审批不通过");
                break;
            case 7:
                holder.tv_status.setText("二级审批关闭");
                break;
            case 8:
                holder.tv_status.setText("二级审批通过");
                break;
            default:
                break;
        }
        holder.tv_landname.setText(bean.getLandname());
        holder.tv_area.setText(bean.getArea() + "㎡");
        holder.tv_contractorid.setText(bean.getContractorid());
        holder.tv_certificatedate.setText(bean.getCertificatedate());
        holder.tv_contracttype.setText(bean.getContracttype());

        holder.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,WarrantDetail_Activity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("warrant_detail",bean);
                intent.putExtra("warrant_bundle",bundle);
                context.startActivity(intent);
                ((ParentActivity)context).overridePendingTransitionFade();
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class mViewHolder extends RecyclerView.ViewHolder {
        LinearLayout ll_item;
        TextView tv_contractnumber;
        TextView tv_status;
        TextView tv_landname;
        TextView tv_area;
        TextView tv_contractorid;
        TextView tv_certificatedate;
        TextView tv_contracttype;

        public mViewHolder(View itemView) {
            super(itemView);
            ll_item = (LinearLayout) itemView.findViewById(R.id.ll_item);
            tv_contractnumber = (TextView) itemView.findViewById(R.id.tv_contractnumber);
            tv_status = (TextView) itemView.findViewById(R.id.tv_status);
            tv_landname = (TextView) itemView.findViewById(R.id.tv_landname);
            tv_area = (TextView) itemView.findViewById(R.id.tv_area);
            tv_contractorid = (TextView) itemView.findViewById(R.id.tv_contractorid);
            tv_certificatedate = (TextView) itemView.findViewById(R.id.tv_certificatedate);
            tv_contracttype = (TextView) itemView.findViewById(R.id.tv_contracttype);
        }
    }
}
